<?php

 namespace HiCommon\Repository;

use HiCommon\Model\Areas;

class AreasRepository extends BaseRepository
{

    public function base_model(){
        return new \HiCommon\Model\Areas();
    }

    /**
     * 分页获取全部数据
     *
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_all($arr_option = [])
    {
        return Areas::commonget($arr_option);
    }



    /**
     * 查询一条数据
     */
    public function get_city_infor(array $where)
    {
        return Areas::where($where)->first();
    }

    /**
     * 查询数据
     */
    public function get_list(array $where)
    {
        return Areas::where($where)->get(['id','name','pid'])->toarray();
    }

    /**
     * 查询数据
     */
    public function get_all_list(array $where)
    {
        return Areas::where($where)->with(['son'=> function($query){
            $query->with('son')->select('id','name','pid');
        }])->get(['id','name','pid'])->toarray();
    }

    /**
     * 根据cityids查询城市和区域
     *
     * @param array $arr_cityids
     *
     * @return \HiCommon\Model\Areas[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_city_area_by_cityids(array $arr_cityids)
    {
        return Areas::whereIn('id',$arr_cityids)->with('son')->select(['id','name','pid'])->get();
    }


}